﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

using ZaxLib.Collections;
using ZaxLib.Web.Writers;
using ZaxLib.Web.Writers.Nodes;

namespace JQueryTest
{
	class Program
	{
		static void Main(string[] args)
		{
			JQueryTest();

			Console.ReadKey();

		}

		public static void DataTest()
		{
			CDataGrid grid = new CDataGrid();
			for (int y = 0; y < 15; y++)
			{
				Dictionary<String, Object> row = new Dictionary<string, object>();
				for (int x = 0; x < 5; x++)
				{
					String key = String.Format("X:{0}", x);
					row[key] = String.Format("{0}", (5 * y) + x);
				}

				grid.AddRow(row);
			}

			grid.Start();
			String head = String.Join("\t", grid.Head.ToArray());
			Console.WriteLine(head);
			do
			{
				ArrayList data = new ArrayList();
				foreach (String cell in grid.Row.Values)
				{
					data.Add(cell);
				}
				String newHead = String.Join("\t", grid.Head.ToArray());
				if (newHead != head)
				{
					head = newHead;
					Console.WriteLine(head);
				}
				Console.WriteLine(String.Join("\t", data.ToArray()));
			} while (grid.Next());

		}

		public static void JQueryTest()
		{
			ArrayList AutoComplete = new ArrayList();
			AutoComplete.Add("\"Blue\"");
			AutoComplete.Add("\"Green\"");
			AutoComplete.Add("\"Red\"");

			//String heightFunc = "MaxHeight";
			//String ColumnSize = "Columns";
			//String ChangeClass = "DemoCode";
			//String PostbackData = "{fieldName: \"Some Value\"}";
			String Text = "\"Original Value\"";
			String ID = "TestID";

			IWriter CodeWriter = new JQWriter();
			INode top = CodeWriter.CreateTopNode();
			INode node = CodeWriter.CreateReadyFunction(top);
			CodeWriter.AddChild(ID, node).SelectorId();
			CodeWriter.AddChild("droppable").Joined();
			node = CodeWriter.AddParam("").ObjectDef();
			INode param = CodeWriter.AddParam("drop", node).VarDef();
			INode func = CodeWriter.AddChild("function", param).Function();
			CodeWriter.AddChild("this", func).Selector();
			node = CodeWriter.AddChild("find").Joined();
			CodeWriter.AddParam("\".placenholder\"").VarDef();
			CodeWriter.AddChild("remove", node).Joined();
			CodeWriter.AddParam("").VarDef();

			CodeWriter.AddChild("\"<li></li>\"", func).Selector();
			node = CodeWriter.AddChild("text").Joined();
			CodeWriter.AddParam("ui.draggable.text()").VarDef();
			CodeWriter.AddChild("appendTo").Joined();
			CodeWriter.AddParam("this").VarDef();

			CodeWriter.AddChild("ui.draggable.remove();", func).RawCode();


			//CodeWriter.AddParam("drop", "function(event, ui){ $(this).find(\".placeholder\").remove(); ui.draggable.remove(); }", node).VarDef();

			//CodeWriter.AddChild("alert('This was successful');", node).RawCode();




			Console.WriteLine(top.Code);
		}
	}
}
